package com.itheima.day05.myobject.test1;

public class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /*@Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }*/
    @Override
    public String toString() {
        return "Student{" + "name='" + getName() + "', age=" + getAge() + "}";
    }

    @Override
    public boolean equals(Object o) {
        // 判断地址值是否一样 一样返回true
        if (this == o) return true;
        // 先判断传入的对象是否为null，在比较两者是否来自同一类，不是返回false
        if (o == null || getClass() != o.getClass()) return false;
        // 向下转型传入对象
        Student student = (Student) o;
        // 比较具体对象里面成员变量的值，都一样则返回true，否则返回false
        if (age != student.age) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

}
